package org.nowcoder.leetcode.bit;

/**
 * Title  : 190. Reverse Bits
 * Source : https://leetcode.cn/problems/reverse-bits/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-08-26
 */

public class LeetCode_190 {
    public int reverseBits(int n) {
        int result = 0;
        for (int i = 0; i < 32 && n != 0; ++i) {
            result |= (n & 1) << (31 - i);
            n >>>= 1; //逻辑右移
        }
        return result;
    }
}
